package com.googlecode.clearnlp.util;

public class Span {
	public int begin;
	public int end;
	public static final int UNKNOWN = -1;
	
	public Span(int begin, int end)
	{
		this.begin = begin;
		this.end = end;
	}
	
	public void addOffset(int offset) 
	{
		begin += offset;
		end += offset;
	}
	
	public Span()
	{
		this(UNKNOWN, UNKNOWN);
	}
	
	public boolean hasValues() {
		return begin != UNKNOWN || end != UNKNOWN;
	}
	
	public String toString() {
		return this.begin + ":" + this.end;
	}
	
	@Override
	public int hashCode() {
		return new Integer(begin).hashCode() ^ new Integer(end).hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof Span))
			return false;
		Span other = (Span) obj;
		return begin == other.begin && end == other.end;
	}
}
